package com.ly.im;

import com.ly.im.netty.WebSocketServer;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @Author LY
 * @create 2024/2/2 9:54
 * @Description web rtc
 */
@SpringBootApplication
@MapperScan(basePackages = {"com.ly.im.repository"})
@Slf4j
public class RtcApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(RtcApplication.class, args);
    }

    @Resource
    private WebSocketServer nettyServer;

    @Override
    public void run(String... args) throws Exception {
        log.info("启动 run start");
        nettyServer.start();
    }

    @PreDestroy
    public void destroy(){
        //停止服务
        if (nettyServer != null){
            nettyServer.shutdown();
        }
    }
}
